package jmine.tec.purge.scheduling;

import jmine.tec.purge.PurgeExecutor;
import jmine.tec.purge.PurgeMessages;
import jmine.tec.purge.dao.PurgeConfigDAO;
import jmine.tec.purge.domain.PurgeConfigIdentifier;
import jmine.tec.scheduling.Action;
import jmine.tec.scheduling.ScheduledJobExecutionContext;

/**
 * Dispatches the purge execution
 * 
 * @author lundberg
 */
public class PurgeAction implements Action {

    private final PurgeConfigDAO purgeConfigDAO;

    private final PurgeConfigIdentifier purgeConfigIdentifier;

    private final PurgeExecutor purgeExecutor;

    /**
     * Constructor
     * 
     * @param purgeConfigDAO purgeConfigDAO
     * @param purgeConfigIdentifier purgeConfigIdentifier
     * @param purgeExecutor purgeExecutor
     */
    public PurgeAction(PurgeConfigDAO purgeConfigDAO, PurgeConfigIdentifier purgeConfigIdentifier, PurgeExecutor purgeExecutor) {
        super();
        this.purgeConfigDAO = purgeConfigDAO;
        this.purgeConfigIdentifier = purgeConfigIdentifier;
        this.purgeExecutor = purgeExecutor;
    }

    /**
     * {@inheritDoc}
     */
    public void execute(ScheduledJobExecutionContext context) throws Exception {
        context.log(PurgeMessages.DISPATCHING_SCHEDULED_PURGE.create());
        purgeExecutor.purge(purgeConfigDAO.findBySystemIdentifier(purgeConfigIdentifier));
        context.log(PurgeMessages.SCHEDULED_PURGE_DISPATCHED.create());
    }
}
